package com.sjy.project.ent.data.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.ent.data.domain.EntData;
import com.sjy.project.ent.data.service.IEntDataService;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 企业档案Controller
 * 
 * @author ljb
 * @date 2022-06-04
 */
@Controller
@RequestMapping("/ent/data")
public class EntDataController extends BaseController
{
    private String prefix = "ent/data";

    @Autowired
    private IEntDataService entDataService;

    @RequiresPermissions("ent:data:view")
    @GetMapping()
    public String data()
    {
        return prefix + "/data";
    }

    /**
     * 查询企业档案列表
     */
    @RequiresPermissions("ent:data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EntData entData)
    {
        startPage();
        List<EntData> list = entDataService.selectEntDataList(entData);
        return getDataTable(list);
    }

    /**
     * 导出企业档案列表
     */
    @RequiresPermissions("ent:data:export")
    @Log(title = "企业档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EntData entData)
    {
        List<EntData> list = entDataService.selectEntDataList(entData);
        ExcelUtil<EntData> util = new ExcelUtil<EntData>(EntData.class);
        return util.exportExcel(list, "企业档案数据");
    }

    /**
     * 新增企业档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业档案
     */
    @RequiresPermissions("ent:data:add")
    @Log(title = "企业档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EntData entData)
    {
        return toAjax(entDataService.insertEntData(entData));
    }

    /**
     * 修改企业档案
     */
    @RequiresPermissions("ent:data:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EntData entData = entDataService.selectEntDataById(id);
        mmap.put("entData", entData);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业档案
     */
    @RequiresPermissions("ent:data:edit")
    @Log(title = "企业档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EntData entData)
    {
        return toAjax(entDataService.updateEntData(entData));
    }

    /**
     * 删除企业档案
     */
    @RequiresPermissions("ent:data:remove")
    @Log(title = "企业档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(entDataService.deleteEntDataByIds(ids));
    }
}
